from whyhow import WhyHow, Triple, Node, Chunk, Relation

# Configure WhyHow client
client = WhyHow(api_key="nCvJRyEylM2W2MyQqQrKJ21t222O3RTqFP1XQU6d", base_url="http://localhost:8000")

# Create workspace
workspace = client.workspaces.create(name="Workspace demo1")

# Create chunk(s)
chunk = client.chunks.create(
    workspace_id=workspace.workspace_id,
    chunks=[Chunk(
        content="preneur and visionary, Sam Altman serves as the CEO of OpenAI, leading advancements in artifici"
    )]
)

# Create triple(s)
triples = [
    Triple(
        head=Node(
            name="Sam Altman",
            label="Person",
            properties={"title": "CEO"}
        ),
        relation=Relation(
            name="runs",
        ),
        tail=Node(
            name="OpenAI",
            label="Business",
            properties={"market cap": "$157 Billion"}
        ),
        chunk_ids=[c.chunk_id for c in chunk]
    )
]

# Create graph
graph = client.graphs.create_graph_from_triples(
    name="Demo Graph",
    workspace_id=workspace.workspace_id,
    triples=triples
)

# Query graph
query = client.graphs.query_unstructured(
    graph_id=graph.graph_id,
    query="Who runs OpenAI?"
)
print(query)